#pragma once
class ResolutionPhase: public GamePhase
{
private:
	Game * g;	//A pointer to the game object
	Map gun;	//For awesome ascii art...
	int currentPlayer;		//An indicator of which player is currently selecting their actions.
public:
	ResolutionPhase(Game * a_game)
	{
		g = a_game;
		currentPlayer = 0;
		gun.loadFile("gun.txt");
	}

	void update(int a_ms)
	{
		if (g->getPlayer(currentPlayer)->getHealth() > 0)
		{
			switch(returnInput())
			{
			case 'y': case 'Y':			//Add to their shame count, and set target to null
				{
					g->getPlayer(currentPlayer)->takeShame();
					g->getPlayer(currentPlayer)->setTarget(NULL);
					for (int i = 0; i < MAX_PLAYERS; ++i)	//Loop through all of the players
					{
						if (g->getPlayer(i)->getTarget() == g->getPlayer(currentPlayer))	//If they were aiming at that player
							g->getPlayer(i)->setTarget(NULL);		//They don't have a target anymore, lol.
					}
					undraw();
					currentPlayer++;
				}
				break;
			case 'n': case 'N':			//Just move to the next player
				{
					undraw();
					currentPlayer++;	
				}
				break;
			default: break;
			}

			getInput(0);

			if (currentPlayer >= MAX_PLAYERS)
			{
				g->setState(OUTCOME);
				currentPlayer = 0;
			}
		}
		else
		{
			undraw();
			currentPlayer++;
		}
	}
	void draw()
	{
		for (int i = 0; i < MAX_PLAYERS; ++i)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),  FOREGROUND_INTENSITY| i+1);
			g->getPlayer(i)->draw(i);
			for (int j = 0; j < MAX_PLAYERS; ++j)		//Re-loop through the players and print a color coded character if they are pointing their gun at this player.
			{
				if (g->getPlayer(j)->getTarget() == g->getPlayer(i))		//If a player is pointing their gun at this player.
				{
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | j+1);
					putchar(219);
				}
			}
			printf("\n");
		}
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), WHITE);
		gotoxy(0, 11);
		printf("Do you want to take a shame token (-$5,000), %s?  (Y/N)\n", g->getPlayer(currentPlayer)->name);

		//TODO:  PRIORITY LOW:  Make this work ---V

		//gun.y = 12;
		//for (int i = 0; i < MAX_PLAYERS; ++i)		//Re-loop through the players and print a color coded ascii gun if they are pointing their gun at this player.
		//{
		//	if (g->getPlayer(i)->getTarget() == g->getPlayer(currentPlayer))		//If a player is pointing their gun at this player.
		//	{
		//		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | i+1);
		//		gun.draw();
		//		gun.x += gun.width;
		//	}
		//}		

	}

	void undraw()
	{
		gotoxy(0,0);
		for (int y = 0; y < 80; ++y)
			for (int x = 0; x < 80; ++x)
				putchar(' ');
	}
};